package CustomDialogs;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
import javax.swing.border.EmptyBorder;
import javax.swing.JList;
import javax.swing.JLabel;

import Main.Aplicacion;

import javax.swing.JScrollPane;


public class DialogListaNodos extends JDialog {

	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel = new JPanel();

	/**
	 * Create the dialog.
	 */
	public DialogListaNodos(Aplicacion padre,String titulo,String[] nodos) {
		super(padre, true);
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(21, 44, 403, 174);
		contentPanel.add(scrollPane);
		
		JList<String> list = new JList<String>();
		scrollPane.setViewportView(list);
		list.setListData(nodos);
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		JLabel lblNodosPentientes = new JLabel(titulo);
		lblNodosPentientes.setBounds(21, 11, 201, 35);
		contentPanel.add(lblNodosPentientes);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.setActionCommand("OK");
				okButton.addActionListener(new ActionListener() {		
					public void actionPerformed(ActionEvent e) {
						cerrarVentana();
					}
				});
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
		}
		
		setLocation(padre.getLocationOnScreen().x+(padre.getWidth()-this.getWidth())/2,padre.getLocationOnScreen().y+(padre.getHeight()-this.getHeight())/2);
		setResizable(false);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setVisible(true);
	}
	
	private void cerrarVentana(){
		dispose();
	}
	
}
